package com.pingtai.ajax.action;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.message.BasicNameValuePair;

import com.pingtai.util.ChangeCharset;
import com.pingtai.util.HttpClientUtils;
import com.pingtai.util.Utils;

public class CookieSave {
	public static void main(String[] args) throws Exception {
		HttpClient client = null;
		client = HttpClientUtils.getHttpClient();
    	HttpGet getMeth = new HttpGet("http://weibo.com/476905600");
    	getMeth.addHeader("Accept-Charset","utf-8,GBK;q=0.7,*;q=0.3");
    	getMeth.addHeader("Connection","keep-alive");
    	getMeth.setHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");
    	getMeth.addHeader("Cookie","SINAGLOBAL=4881056891754.27.1378798357905; un=mjjsojava@163.com; myuid=3945635581; SUB=AQ%2FuAs%2BpATD8iERrVEV2e4IdIHaijOYzYK46wfPfqDjPo7b4OrozvEhdKh2FXVMEr1UqilN%2BJ7w3KDg5e2AGtbWyEX4RU2LxAmWlMRACKUCg; wvr=5; UUG=usr431_26; SUE=es%3D5692f44d7bbef1a740af3ac6450fbfdb%26ev%3Dv1%26es2%3De8808871388620b89c27c86ef0b9d031%26rs0%3DqsnP9Igo8DxpLrfmmNKoBee9y9vkWdt%252BP%252FzQhsxEpO40pirISNCxNT9yLi8Nn31h12VoU%252BTSRrHjiyDSovg9NzOMdL6pHSUPwn7QHeAtmKaKgVR2i0yJp71tm%252FSO35OzXYaTWrbk93pS5sp5lwcWtcazBy145iAMKs%252FnbThyr70%253D%26rv%3D0; SUP=cv%3D1%26bt%3D1387241247%26et%3D1387327647%26d%3Dc909%26i%3Dffc4%26us%3D1%26vf%3D0%26vt%3D0%26ac%3D0%26st%3D0%26uid%3D3944411338%26name%3Dsmxread3%2540163.com%26nick%3D%25E5%25B0%258F2%25E5%2593%25A5%25E5%2593%25A5%25E4%25B9%2590%25E5%259B%25AD%26fmp%3D%26lcp%3D; SUS=SID-3944411338-1387241247-XD-a12oz-b84370d1a42c0c18c1fed5ebd03a2bf4; ALF=1389833247; SSOLoginState=1387241247; V5REG=usr19181; UV5=usr319_150; _s_tentry=login.sina.com.cn; WBtopGlobal_register_version=4433c509f4011411; UOR=itbbs.pconline.com.cn,widget.weibo.com,login.sina.com.cn; Apache=8669229347724.468.1387241198317; ULV=1387241198323:45:9:3:8669229347724.468.1387241198317:1387174592689");
    	getMeth.addHeader("Host","weibo.com");
    	getMeth.addHeader("Origin","http://weibo.com");
    	getMeth.addHeader("Referer","http://weibo.com/1975894555/AiR3hbqsY?mod=weibotime&type=repost");
    	getMeth.addHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1 QIHU 360SE");
    	getMeth.addHeader("X-Requested-With","XMLHttpRequest");
        HttpResponse response = client.execute(getMeth);
        List<Cookie> cookies = ((AbstractHttpClient) client).getCookieStore().getCookies();
        String s = "";
        System.out.println(cookies.size());
		for(int i=0;i<cookies.size();i++){
			Cookie cookie = cookies.get(i);
			s += cookie.getName()+"="+cookie.getValue()+";";
//			xinlangDao.update(loginUser);
		}
		System.out.println(s);
		InputStream in = response.getEntity().getContent();
		String msg = Utils.InputStreamTOString(in, "utf-8");
    	msg = ChangeCharset.fromEncodedUnicode(msg.toCharArray(), 0, msg.length());
		//System.out.println(msg);

	    }
}
